package com.yunb.controller;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 用于记录大厂使用redis 的方式和注意事项
 */
@RestController
public class LearnBigController {

    @Resource
    private Redisson redisson;

    @GetMapping("/bl")
    public String testBl(){
        RBloomFilter<Object> namebl = redisson.getBloomFilter("flname");
        //初始化布隆过滤器 大小 误判率

        namebl.tryInit(10000L,0.01);
        for (int i = 1; i <= 10000; i++) {
            namebl.add("flname"+ i);
        }
        //判断不存在于布伦过滤器的元素
        List<String> notExistList = new ArrayList<>();
        for (int i = 1; i < 10000 ; i++) {
            String str = "flname" + i;
            if (!namebl.contains(str)){
                notExistList.add(str);
            }
        }

        if (null!=notExistList && notExistList.size()>0){
            System.out.println("误判次数:"+notExistList.size());
        }
        System.out.println("误判次数为0");
        return "test";
    }
}
